#include "fepch.h"
#include "VertexArray.h"

#include "Renderer.h"
#include "FysicsEngine/Platform/OpenGL/OpenGLVertexArray.h"

namespace Fysics {

	VertexArray* VertexArray::Create()
	{
		switch (Renderer::GetAPI())
		{
		case RendererAPI::API::None:   // FE_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr;
		case RendererAPI::API::OpenGL:  return new OpenGLVertexArray();
		}

		//FE_CORE_ASSERT(false, "Unknown RendererAPI!");
		return nullptr;
	}

	std::shared_ptr<VertexArray> CreateVertexArray(float* vertices, unsigned int vCount,
		unsigned int* indices, unsigned int iCount, BufferLayout layout)
	{
		std::shared_ptr<IndexBuffer> indexBuffer;
		std::shared_ptr<VertexArray> vertexArray;
		std::shared_ptr<VertexBuffer> vertexBuffer;

		vertexArray.reset(VertexArray::Create());		
		vertexBuffer.reset(VertexBuffer::Create(vertices, vCount * sizeof(float)));
		vertexBuffer->SetLayout(layout);
		vertexArray->AddVertexBuffer(vertexBuffer);
		indexBuffer.reset(IndexBuffer::Create(indices, iCount));
		vertexArray->SetIndexBuffer(indexBuffer);
		return vertexArray;
	}

}